import 'dart:convert';

import 'package:encrypt/encrypt.dart' as encrypt;
import 'package:encrypt/encrypt.dart';

const String _key = '692B83791A2F7774';
const String _iv = 'D29F1190125B741A';
String aesDecrypted(String data) {
  //加密key
  final key = encrypt.Key.fromUtf8(_key);
  //偏移量
  final iv = encrypt.IV.fromUtf8(_iv);
  //设置cbc模式
  final encrypter = encrypt.Encrypter(
      encrypt.AES(key, mode: encrypt.AESMode.cbc, padding: 'PKCS7'));
  return encrypter.decrypt(Encrypted.fromBase64(data), iv: iv);
}

String aesEncrypt(Map<String, dynamic> params) {
  //加密key
  final key = encrypt.Key.fromUtf8(_key);
  //偏移量
  final iv = encrypt.IV.fromUtf8(_iv);
  //设置cbc模式
  final encrypter = encrypt.Encrypter(
      encrypt.AES(key, mode: encrypt.AESMode.cbc, padding: 'PKCS7'));
  return encrypter.encrypt(jsonEncode(params), iv: iv).base64;
}
